package com.quexin.pickmedialib;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import java.util.Objects;

/**
 * 系统媒体：图片、音频、视频
 */
public class MediaModel implements Parcelable {

    private String path;
    private String name;
    private String duration;
    private String size;
    private String mimeType;
    private int width;
    private int height;

    private long sizeV;
    private long durationV;

    // 0图片、1音频、2视频
    private int flag;

    public MediaModel() {

    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDuration() {
        return duration;
    }

    public void setDuration(long duration, String duration1) {
        durationV = duration;
        this.duration = duration1;
    }

    public long getDurationV() {
        return durationV;
    }

    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        if (TextUtils.isEmpty(mimeType)) {
            this.mimeType = "";
        } else {
            int index = mimeType.lastIndexOf("/") + 1;
            if (index > 1) {
                this.mimeType = mimeType.substring(index).toUpperCase();
            } else {
                this.mimeType = mimeType.toUpperCase();
            }
        }
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public long getSizeV() {
        return sizeV;
    }

    public void setSizeV(long sizeV) {
        this.sizeV = sizeV;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public int getFlag() {
        return flag;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MediaModel that = (MediaModel) o;
        return path.equals(that.path);
    }

    @Override
    public int hashCode() {
        return Objects.hash(path);
    }

    protected MediaModel(Parcel in) {
        path = in.readString();
        name = in.readString();
        duration = in.readString();
        size = in.readString();
        mimeType = in.readString();
        width = in.readInt();
        height = in.readInt();
        sizeV = in.readLong();
        durationV = in.readLong();
        flag = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(path);
        dest.writeString(name);
        dest.writeString(duration);
        dest.writeString(size);
        dest.writeString(mimeType);
        dest.writeInt(width);
        dest.writeInt(height);
        dest.writeLong(sizeV);
        dest.writeLong(durationV);
        dest.writeInt(flag);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<MediaModel> CREATOR = new Creator<MediaModel>() {
        @Override
        public MediaModel createFromParcel(Parcel in) {
            return new MediaModel(in);
        }

        @Override
        public MediaModel[] newArray(int size) {
            return new MediaModel[size];
        }
    };
}
